
/**
 * Project Name:cats-core-impl
 * File Name:RoleDao.java
 * Package Name:com.catsic.core.role.dao
 * Date:2014年2月27日下午1:31:44
 * Copyright (c) 2014, oa.catsic.com All Rights Reserved.
 */
 
package com.catsic.core.role.dao;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;

import com.catsic.base.BaseDao;
import com.catsic.core.entity.Organ;
import com.catsic.core.entity.Role;


/**
 * ClassName: RoleDao
 * Description: 角色Dao接口类
 * date: 2014年2月27日 下午1:31:44
 * author: yangyd
 */
public interface RoleDao extends BaseDao<Role,String>{
	
	@Query("select r from Role r")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	List<Role> findAllRole();
	
	@Query("select r from Organ o join o.bindRoles r where o.id=?1")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	List<Role> findByOrganId(String organId);

	@Query("select r from User u join u.roles r where u.id=?1 and r.id !=1")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	List<Role> findByUserId(String userId);
	
	@Query("select o from Role r join r.organs o where r.id=?1")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	List<Organ> findOrganById(String id);
	
	@Query("select r.id,r.name,r.status from Role r join r.resources rs where rs.id = ?1")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	List<Role> findRoleByResourceId(String resourceId);
	
	@Query("select r from Role r join r.menus ms where ms.id=?1")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	List<Role> findRoleByMenuId(String id);
}
